package com.cnap.model.stage;

import cn.hutool.core.text.CharSequenceUtil;
import com.cnap.db.entity.StagePO;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 单个阶段的展示类
 *
 * @author xc
 **/
public class SingleStageVO {
    // 服务id
    private String svcId;
    // 阶段类型
    private String type;
    // 额外信息
    private List<Map<String, String>> extraInfo;
    // 错误信息
    private String errorMsg;
    // 是否执行成功，  true: 成功，false: 失败
    private boolean success;
    // 二级分类
    private String detailType;
    // 二级分类信息
    private String message;

    /**
     * get
     *
     * @return Message
     */
    public String getMessage() {
        return message;
    }

    /**
     * set
     *
     * @param message message
     */
    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * get
     *
     * @return DetailType
     */
    public String getDetailType() {
        return detailType;
    }

    /**
     * set
     *
     * @param detailType detailType
     */
    public void setDetailType(String detailType) {
        this.detailType = detailType;
    }

    /**
     * get
     *
     * @return SvcId
     */
    public String getSvcId() {
        return svcId;
    }

    /**
     * set
     *
     * @param svcId svcId
     */
    public void setSvcId(String svcId) {
        this.svcId = svcId;
    }

    /**
     * get
     *
     * @return Type
     */
    public String getType() {
        return type;
    }

    /**
     * set
     *
     * @param type type
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * get
     *
     * @return ExtraInfo
     */
    public List<Map<String, String>> getExtraInfo() {
        return extraInfo;
    }

    /**
     * set
     *
     * @param extraInfo extraInfo
     */
    public void setExtraInfo(List<Map<String, String>> extraInfo) {
        this.extraInfo = extraInfo;
    }

    /**
     * get
     *
     * @return ErrorMsg
     */
    public String getErrorMsg() {
        return errorMsg;
    }

    /**
     * set
     *
     * @param errorMsg errorMsg
     */
    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    /**
     * get
     *
     * @return Success
     */
    public boolean isSuccess() {
        return success;
    }

    /**
     * set
     *
     * @param success success
     */
    public void setSuccess(boolean success) {
        this.success = success;
    }

    /**
     * po转成vo
     *
     * @param stagePO po
     * @return vo
     */
    public static SingleStageVO fromPO(StagePO stagePO) {
        // 有可能为空
        if (Objects.isNull(stagePO)) {
            return null;
        }
        SingleStageVO singleStageVO = new SingleStageVO();
        singleStageVO.setSvcId(stagePO.getServiceId());
        singleStageVO.setType(stagePO.getType());
        singleStageVO.setExtraInfo(stagePO.getExtraInfo());
        // 根据error判断是否成功
        singleStageVO.setSuccess(CharSequenceUtil.isEmpty(stagePO.getError()));
        singleStageVO.setErrorMsg(stagePO.getError());
        singleStageVO.setDetailType(stagePO.getDetailType());
        singleStageVO.setMessage(StageEnum2.getStageEnum2WithParam(stagePO.getDetailType(), stagePO.getCloudScope(), stagePO.getArch()).getMessage());
        return singleStageVO;
    }
}
